﻿using System;
using System.IO;
using System.Windows.Forms;

namespace FWF.Logging.Viewer
{
    /// <summary>
    /// 
    /// </summary>
    public partial class frmExport : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="frmExport"/> class.
        /// </summary>
        public frmExport()
        {
            InitializeComponent();

            //
            radByMinute.Checked = true;
        }

        /// <summary>
        /// Gets or sets the file path.
        /// </summary>
        /// <value>The file path.</value>
        public string FilePath
        {
            get;
            set;
        }

        /// <summary>
        /// Handles the Click event of the btnExport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnExport_Click( object sender, EventArgs e )
        {
            //
            string filePath = Program.FilePath;

            // If viewing a saved file in Log Viewer, then update the export file name
            // to the name of the file opened, but with a .xml extension
            if ( !string.IsNullOrEmpty( filePath ) )
            {
                string fileName = Path.GetFileNameWithoutExtension( filePath );

                //
                diaSaveResults.FileName = fileName;
            }
            else
            {
                //
                diaSaveResults.FileName = "LogViewerResults." + DateTime.Now.ToString( "MM.dd.yyyy" );
            }
            
            DialogResult result = diaSaveResults.ShowDialog( this );

            if ( result != DialogResult.OK && result != DialogResult.Yes )
            {
                return;
            }

            //
            FilePath = diaSaveResults.FileName;

            //if ( radBySecond.Checked )
            //{
            //    this.Granularity = ExportGranularity.BySecond;
            //}
            //else if ( radByMinute.Checked )
            //{
            //    this.Granularity = ExportGranularity.ByMinute;
            //}
            //else if ( radByHour.Checked )
            //{
            //    this.Granularity = ExportGranularity.ByHour;
            //}
            //else if ( radSummary.Checked )
            //{
            //    this.Granularity = ExportGranularity.Summary;
            //}
            //else if ( radComplete.Checked )
            //{
            //    this.Granularity = ExportGranularity.Complete;
            //}

            Close();
        }
    }
}
